# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import sqlite3

class MtimespiderPipeline(object):
    def __init__(self):
        self.conn = sqlite3.connect('mtime.db')
        self.c = self.conn.cursor()
        
    def process_item(self, item, spider):
        #存储数据到表里
        #先创建一个表
        self.c.execute('''
            create table if not exists movies_tb(
                id integer primary key  autoincrement,
                movie_name,
                movie_url,
                director,
                actor,
                movie_type,
                introduce,
                point
            )
        ''')
        self.c.execute('insert into movies_tb values (null,?,?,?,?,?,?,?)',
                       (item['movie_name'],item['movie_url'],item['director'],item['actor'],item['movie_type'],item['introduce'],item['point']))
        self.conn.commit()
        
    def close_spider(self):
        #关闭数据库
        self.c.close()
        self.conn.close()